package com.sec.android.app.myfiles.module.preview;

import android.content.Context;
import android.os.Bundle;

import com.sec.android.app.myfiles.facade.MyFilesFacade;
import com.sec.android.app.myfiles.feature.PrivateModeMgr;
import com.sec.android.app.myfiles.fragment.AbsMyFilesFragment;
import com.sec.android.app.myfiles.module.abstraction.AbsReloadStrategyImp;
import com.sec.android.app.myfiles.module.abstraction.FileRecord;
import com.sec.android.app.myfiles.navigation.NavigationInfo;

/**
 * Created by daesu83.kim on 2015-09-24.
 */
public class PreviewCompressReloadStrategyImp extends AbsReloadStrategyImp {
    public PreviewCompressReloadStrategyImp(Context context, NavigationInfo navigationInfo) {
        super(context, navigationInfo);
    }

    @Override
    public void reload(ReloadCause cause, Bundle extras, int event) {
        if (cause == ReloadCause.MediaUnmounted) {
            if (mNavigationInfo != null) {
                FileRecord record = mNavigationInfo.getCurRecord();
                PrivateModeMgr privateMgr = PrivateModeMgr.getInstance(mContext);
                if (record != null && record.getStorageType() == FileRecord.StorageType.Compress) {
                    FileRecord archive = ((CompressFileRecord) record).getArchiveRecord();
                    if (archive != null) {
                        String fullPath = archive.getFullPath();
                        if (!privateMgr.isPrivateDirMounted() && privateMgr.isPrivateModePath(fullPath)) {
                            AbsMyFilesFragment fragment = mNavigationInfo.getCurFragment();
                            if (fragment != null) {
                                MyFilesFacade.goHome(fragment.getProcessId(), null, mContext);
                            }
                        }
                    }
                }
            }
        }
    }
}
